import urllib.request
url = "http.//www.douban.com"
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.55"}
data = bytes(urllib.parse.urlencode({'name':'eric'}),encoding = "utf-8")
req = urllib.request.Request(url=url,data= data,headers=headers,method="POST")#需要一个对象进行包装
#请求对象构建好了，下面需要一个响应
response = urllib.request.urlopen(req)
print(response.read().decode("utf-8"))